package edu.hitsz.aircraft;

import edu.hitsz.application.ImageManager;
import edu.hitsz.application.Main;
import edu.hitsz.shoot.ShootScatteringByHero;
import edu.hitsz.shoot.ShootDirectByHero;

/**
 * 英雄飞机，游戏玩家操控
 * @author hitsz
 */
public class HeroAircraft extends AbstractAircraft {


    /**
     * @param locationX 英雄机位置x坐标
     * @param locationY 英雄机位置y坐标
     * @param speedX 英雄机射出的子弹的基准速度（英雄机无特定速度）
     * @param speedY 英雄机射出的子弹的基准速度（英雄机无特定速度）
     * @param hp    初始生命值
     */
    private HeroAircraft(int locationX, int locationY, int speedX, int speedY, int hp) {
        super(locationX, locationY, speedX, speedY, hp);
        this.type = 0;
        this.shootStrategy = new ShootDirectByHero();
        this.shootNum = 1;
        this.power = 30;
        this.direction = -1;
    }


    /** 使用volatile关键字防止指令重排 */
    private volatile static HeroAircraft h;

    /** 双重检查锁定 */
    public static HeroAircraft getInstance(){
        if (h == null){
            synchronized (HeroAircraft.class){
                if(h == null){
                    h = new HeroAircraft(Main.WINDOW_WIDTH / 2,
                            Main.WINDOW_HEIGHT - ImageManager.HERO_IMAGE.getHeight() ,
                            0, 0, 100);
                }
            }
        }
        return h;
    }

    @Override
    public void forward() {
        // 英雄机由鼠标控制，不通过forward函数移动
    }

    public void getBulletProp(){
        this.shootNum = 3;
        this.shootStrategy = new ShootScatteringByHero();
    }

    public void bulletPropExpire(){
        this.shootNum = 1;
        this.shootStrategy = new ShootDirectByHero();
    }

}
